﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace FAQFrameworks
{
    public class RegexValid
    {
        public string Message { get; set; }

        Regex regex;

        public RegexValid(string regex)
            : this(regex, null)
        {

        }

        public object Value { get; set; }

        public bool Continue { get; set; }

        public RegexValid(string strRegex, string message)
        {
            this.regex = new Regex(strRegex, RegexOptions.Compiled);
            this.Message = message;

            this.Continue = false;
        }

        public void ValidateHandler
            (object sender, ValidateEventArgs e)
        {
            string str = this.Value as string;
            bool isMatch = regex.IsMatch(str);
            e.Continue = this.Continue;
            if (!isMatch)
            {
                e.IsValid = false;
                e.Messsge = this.Message;
            }
        }
    }
}
